package com.gexiaobao.pigeon.ui.adapter

import android.annotation.SuppressLint
import android.widget.CheckBox
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.CartCouponListResponse
import com.gexiaobao.pigeon.databinding.ItemCartCouponBinding

/**
 * @Author      : hxw
 * @Date        : 2023/6/28 14:58
 * @Describe    :
 */
class CouponListAdapter : BaseQuickAdapter<CartCouponListResponse.ListBean, DataBindBaseViewHolder>(R.layout.item_cart_coupon) {

    private var mCheckedListener: OnCheckedClickListener? = null

    @SuppressLint("NotifyDataSetChanged")
    override fun convert(holder: DataBindBaseViewHolder, item: CartCouponListResponse.ListBean) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemCartCouponBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        val checkBoxCoupon = holder.getView<CheckBox>(R.id.checkBoxCoupon)
        checkBoxCoupon.setOnCheckedChangeListener { _, isChecked ->
            mCheckedListener?.onBoxCheckedListener(isChecked, holder.layoutPosition)
        }
    }

    interface OnCheckedClickListener {
        fun onBoxCheckedListener(isChecked: Boolean, position: Int)
    }

    fun setOnBoxCheckedClickListener(onCheckedClick: OnCheckedClickListener) {
        mCheckedListener = onCheckedClick
    }
}